home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 03 Pathfinding with Astar / 02 Higgins / Listing1.cpp next >
Encoding:
Text File  |  2001-12-09  |  1.5 KB  |  46 lines

  1. /* Copyright (C) Dan Higgins, 2001. 
  2.  * All rights reserved worldwide.
  3.  *
  4.  * This software is provided "as is" without express or implied
  5.  * warranties. You may freely copy and compile this source into
  6.  * applications you distribute provided that the copyright text
  7.  * below is included in the resulting source code, for example:
  8.  * "Portions Copyright (C) Dan Higgins, 2001"
  9.  */
  10.  
  11. // Excerpt from AStarMachine<TGoal, TStorage, TMap>'s run method.
  12.  
  13. // Infinite loop. The goal will tell us when we are done.
  14. for(;;)
  15. {    
  16.     // used for time-slicing
  17.     this->mRevolutions++; 
  18.  
  19.     // get the best choice so far
  20.     this->mCurrentNode = this->RemoveCheapestOpenNode();
  21.  
  22.     // if == true, then its likely that we are not at the
  23.     // goal and we have no more nodes to search through
  24.     if(this->mGoal.GetIsPathFinished(this->mCurrentNode))
  25.         break;
  26.  
  27.     // for all 8 neighbor tiles, examine them by checking
  28.     // their TileOpen status, and putting them on the
  29.     // appropriate A* lists. (code not shown)
  30.     
  31.     // add this node to closed list now
  32.     this->AddNodeToClosedList(this->mCurrentNode);
  33.  
  34.     // Should we pause? (used in time-slicing)
  35.     if(this->mGoal.ShouldPause(this->mCurrentRevolutions))
  36.         break;
  37.  
  38.     // if == true, this means we have exceeded our max
  39.     // pathfinding revolutions and should give up.
  40.     if(this->mGoal.ShouldGiveUp(this->mRevolutions))
  41.         break;
  42.  
  43.     // used for time-slicing
  44.     this->mCurrentRevolutions++; 
  45. }
  46.